package mars.ns

import mars.ns.core._;
import mars.ns.events.SimulationEvent
/**
 *  amount is the amount of events to complete.
 */
class EventSimulation[T<: Node](network: Network[T],isEnded: Int => Boolean,var events:List[SimulationEvent[T]]) 
	extends Simulation(network, isEnded){
	
  /**
     * Constructor giving a network and an amount of iterations that the simulation may run
     */
    def this(network : Network[T],iterations : Int, events:List[SimulationEvent[T]]) =
      this(network, Simulation.toMaxIterationFunction(iterations),events )
      
	override def nextIteration {
        val node = events.head.getNode
    	val nodeList : List[T] = events.head.executeAction
    	if(events.head.linkAdded) {
    	    val list = node.getLinksTo(nodeList.apply(0))
    	    list.foreach(arg=>notifyLinkAdded(node,nodeList.apply(0),arg.getType))
    	}
    	if(events.head.nodeChanged) nodeList.foreach(arg => notifyNodeChanged(arg))
    	events = events.drop(1)
    }
}